//
//  YTFUserModel.m
//  weibo_yoo_OC
//
//  Created by pro on 16/2/28.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "YTFUserModel.h"

@interface YTFUserModel ()<NSCoding>

@end

@implementation YTFUserModel

-(instancetype)initWithDict:(NSDictionary*)dict{
    //调用父类方法
    self = [super init];
    
    //KVC
    [self setValuesForKeysWithDictionary:dict];
    
    return self;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}


//保存到沙盒中
-(void)saveUserInfo{
    //获取沙盒路劲
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    
    //拼接文件路径
    NSString *filePath = [path stringByAppendingPathComponent:@"info.cr"];
    
    //写入沙盒
    [NSKeyedArchiver archiveRootObject:self toFile:filePath];
}

//归档
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeFloat:self.expires_in forKey:@"expires_in"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.profile_image_url forKey:@"profile_image_url"];
    [aCoder encodeObject:self.screen_name forKey:@"screen_name"];
}



- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder{
    self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
    self.uid = [aDecoder decodeObjectForKey:@"uid"];
    self.profile_image_url = [aDecoder decodeObjectForKey:@"profile_image_url"];
    self.screen_name = [aDecoder decodeObjectForKey:@"screen_name"];
    self.expires_in = [aDecoder decodeFloatForKey:@"expires_in"];

    return self;
}




@end
